package com.zf.shuashua.api;

import android.net.Uri;
import android.text.TextUtils;

import com.aliyun.svideo.base.sts.StsInfo;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.vise.xsnow.http.mode.DownProgress;
import com.zf.shuashua.BuildConfig;
import com.zf.shuashua.ShuaApplication;
import com.zf.shuashua.bean.ActionThirdAsk;
import com.zf.shuashua.bean.AddBlack;
import com.zf.shuashua.bean.AdvertInfo;
import com.zf.shuashua.bean.AdvertList;
import com.zf.shuashua.bean.AdvertReport;
import com.zf.shuashua.bean.BaseData;
import com.zf.shuashua.bean.BaseListData;
import com.zf.shuashua.bean.BindWX;
import com.zf.shuashua.bean.BlackList;
import com.zf.shuashua.bean.ButtleDoubleStatus;
import com.zf.shuashua.bean.CommentBean;
import com.zf.shuashua.bean.ConfigAdvertList;
import com.zf.shuashua.bean.ConfigInfo;
import com.zf.shuashua.bean.EditMe;
import com.zf.shuashua.bean.FansList;
import com.zf.shuashua.bean.FocusList;
import com.zf.shuashua.bean.FocusType;
import com.zf.shuashua.bean.ForwardIncreaseBean;
import com.zf.shuashua.bean.GiftReport;
import com.zf.shuashua.bean.GoldBean;
import com.zf.shuashua.bean.Guafen;
import com.zf.shuashua.bean.InviteStatus;
import com.zf.shuashua.bean.LikeVideo;
import com.zf.shuashua.bean.ListVideo;
import com.zf.shuashua.bean.LogBean;
import com.zf.shuashua.bean.LoginBean;
import com.zf.shuashua.bean.Me;
import com.zf.shuashua.bean.NotificationInfo;
import com.zf.shuashua.bean.Notificattuonpraise;
import com.zf.shuashua.bean.OtherLoginBean;
import com.zf.shuashua.bean.ReplyStoreBean;
import com.zf.shuashua.bean.Reward;
import com.zf.shuashua.bean.RewardPoint;
import com.zf.shuashua.bean.StoreBean;
import com.zf.shuashua.bean.ToggleLikeBean;
import com.zf.shuashua.bean.UpImage;
import com.zf.shuashua.bean.VerifyCode;
import com.zf.shuashua.bean.VideoInfo;
import com.zf.shuashua.bean.VideoPointInfo;
import com.zf.shuashua.bean.WXLoginBean;
import com.zf.shuashua.bean.Wallet;
import com.zf.shuashua.bean.advert.AdvertConfigList;
import com.zf.shuashua.bean.advert.MistakeConfigBean;
import com.zf.shuashua.bean.comment.CommentEntity;
import com.zf.shuashua.bean.comment.VideoCommentEntity;
import com.zf.shuashua.utils.MD5Util;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observable;

public class HttpData {

    //获取个人信息
    public void getMe(ACallback<Me> callback) {
        ViseHttp.GET("me")
                .tag("me")
                .request(callback);
    }

    //修改个人信息
    public void getEditMe(String name, String sex, String signature, String birthday, String province_code, String city_code, String district_code, String city, String avatar, AbsCallback<BaseData<EditMe>> callback) {
        ViseHttp.POST("user/update/info")
                .addParam("name", name)
                .addParam("sex", sex)
                .addParam("signature", signature)
                .addParam("birthday", birthday)
                .addParam("province_code", province_code)
                .addParam("city_code", city_code)
                .addParam("district_code", district_code)
                .addParam("city", city)
                .addParam("avatar", avatar)
                .request(callback);
    }

    public void getHomeData(int page, int limit, ACallback<BaseListData<VideoInfo>> callback) {
        ViseHttp.GET("home")
                .addParam("page", Integer.toString(page))
                .addParam("limit", Integer.toString(limit))
                .request(callback);
    }

    public void getVideoPoint(int video_id, long time, String sign, int reopen, AbsCallback<BaseData<VideoPointInfo>> callback) {
        Map<String, String> headers = new HashMap<>();
        if (reopen == 1) {
            headers.put("reopen", reopen + "");
        }
        ViseHttp.POST("video/get/point")
                .addParam("video_id", Integer.toString(video_id))
                .addParam("time", Long.toString(time))
                .addHeaders(headers)
                .addParam("sign", sign)
                .request(callback);
    }

    public void getConfigInfo(AbsCallback<BaseData<ConfigInfo>> callback) {
        ViseHttp.POST("setting/init")
                .request(callback);
    }

    public void getAdvertConfig(AbsCallback<BaseData<ConfigAdvertList>> callback) {
        ViseHttp.GET("setting/advert_init")
                .request(callback);
    }

    public void getNewAdvertConfig(AbsCallback<BaseData<AdvertConfigList>> callback) {
        ViseHttp.GET("advert/sourceData")
                .retryDelayMillis(3000).retryCount(3)
                .request(callback);
    }

    public void getBubbleDoubleStatus(AbsCallback<BaseData<ButtleDoubleStatus>> callback) {
        ViseHttp.GET("user/bubbleDoubleStatus")
                .request(callback);
    }

    public void getEntryStatus(String secretCode, AbsCallback<BaseData<InviteStatus>> callback) {
        ViseHttp.POST("activity/invite/getEntryStatus")
                .addParam("secret_code", secretCode)
                .request(callback);
    }

    public void getPatchMistakeSettings(String city, AbsCallback<BaseData<MistakeConfigBean>> callback) {
        ViseHttp.GET("advert/getPatchMistakeSettings")
                .addParam("city", city)
                .retryDelayMillis(3000).retryCount(3)
                .request(callback);
    }

    public Observable<String> getPatchMistakeSettings(String city) {
        return ViseHttp.GET("advert/getPatchMistakeSettings")
                .retryDelayMillis(3000).retryCount(3)
                .request(String.class);
    }

    public void uploadLog(ACallback<BaseData<LogBean>> callback, String video_id, long length, int index) {
        ViseHttp.POST("video/play/log")
                .addParam("video_id", video_id)
                .addParam("length", length + "")
                .addParam("index", index + "")
                .request(callback);
    }

    public void advertRecord(String video_id, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/record")
                .addParam("video_id", video_id)
                .request(callback);
    }

    //获取我喜欢的视频
    public void getLikeVideo(String user_id, int page, ACallback<LikeVideo> callback) {
        ViseHttp.GET("user/video/like/list")
                .tag("like")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    //获取我喜欢的视频
    public Observable<String> getLikeVideo(String user_id, int page) {
        return ViseHttp.GET("user/video/like/list")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .addParam("limit", "20")
                .request(String.class);
    }

    //获取我发布的视频
    public void getListVideo(String user_id, int page, ACallback<ListVideo> callback) {
        ViseHttp.GET("user/video/list")
                .tag("list")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .request(callback);
    }


    //获取我发布的视频
    public Observable<String> getListVideo(String user_id, int page) {
        return ViseHttp.GET("user/video/list")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .addParam("limit", "20")
                .request(String.class);
    }


    public void getFollowVideo(int page, ACallback<BaseListData<VideoInfo>> callback) {
        ViseHttp.GET("user/video/follow/list")
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    //获取登录验证码
    public void getVerifyCode(String phoneNumber, ACallback<VerifyCode> callback) {
        ViseHttp.POST("sms/verify-code")
                .addParam("mobile", phoneNumber)
                .request(callback);
    }

    //登录
    public void login(String phoneNumber, String code, ACallback<LoginBean> callback) {
        ViseHttp.POST("oauth/sms")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("mobile", phoneNumber)
                .addParam("code", code)
                .addParam("open_id", Store.getInstance().getOpenId())
                .addParam("type", Store.getInstance().getType())
                .request(callback);
    }

    //一键登录
    public void oneLogin(String token, String opToken, String operator, ACallback<LoginBean> callback) {
        ViseHttp.POST("oauth/oneclick")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .tag("oneclick")
                .addParam("sqtoken", token)
                .addParam("opToken", opToken)
                .addParam("operator", operator)
                .request(callback);
    }

    //新登录2020 07 13
    public void thirdLogin(String type, String open_id, String nick_name, String avatar, String sex, String city, String email, String province, String country, String language, ACallback<BaseData<OtherLoginBean>> callback) {
        ViseHttp.POST("login/thirdLogin")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("type", type)//必填
                .addParam("open_id", open_id)//必填
                .addParam("nick_name", nick_name)//如果没有请传空
                .addParam("avatar", avatar)//如果没有请传空
                .addParam("sex", sex)//可选
                .addParam("city", city)//可选
                .addParam("email", email)//可选
                .addParam("province", province)//可选
                .addParam("country", country)//可选
                .addParam("language", language)//可选
                .request(callback);
    }


    //新绑定2020 07 13
    public void bindThird(String type, String open_id, String nick_name, String avatar, String sex, String city, String email, String province, String country, String language, ACallback<BindWX> callback) {
        ViseHttp.POST("bind/bindThird")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("type", type)//必填
                .addParam("open_id", open_id)//必填
                .addParam("nick_name", nick_name)//如果没有请传空
                .addParam("avatar", avatar)//如果没有请传空
                .addParam("sex", sex)//可选
                .addParam("city", city)//可选
                .addParam("email", email)//可选
                .addParam("province", province)//可选
                .addParam("country", country)//可选
                .addParam("language", language)//可选
                .request(callback);
    }


    //微信登录
    public void wxLogin(String code, AbsCallback<BaseData<WXLoginBean>> callback) {
        ViseHttp.POST("login/wechat")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("code", code)
                .request(callback);
    }

    //微博登录
    public void wbLogin(String uid, String access_token, ACallback<BaseData<OtherLoginBean>> callback) {
        ViseHttp.POST("login/weibo")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("uid", uid)
                .addParam("access_token", access_token)
                .request(callback);
    }

    //QQ登录
    public void qqLogin(String open_id, String access_token, ACallback<BaseData<OtherLoginBean>> callback) {
        ViseHttp.POST("login/qq")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("open_id", open_id)
                .addParam("access_token", access_token)
                .request(callback);
    }

    //绑定微信
    public void bindWX(String code, ACallback<BindWX> callback) {
        ViseHttp.POST("bind/wechat")
                .addParam("code", code)
                .request(callback);
    }


    //绑定QQ
    public void bindQQ(String access_token, String uid, ACallback<BindWX> callback) {
        ViseHttp.POST("bind/qq")
                .addParam("access_token", access_token)
                .addParam("open_id", uid)
                .request(callback);
    }


    //绑定微博
    public void bindSINA(String access_token, String uid, ACallback<BindWX> callback) {
        ViseHttp.POST("bind/weibo")
                .addParam("access_token", access_token)
                .addParam("uid", uid)
                .request(callback);
    }


    //获取我关注列表
    public void getFocusList(String user_id, int page, ACallback<FocusList> callback) {
        ViseHttp.GET("user/follow/list")
                .tag("getFocusList")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    //获取我关注列表
    public Observable<String> getFocusList(String user_id, int page) {
        return ViseHttp.GET("user/follow/list")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .addParam("limit", "20")
                .request(String.class);
    }


    //获取我的粉丝列表
    public void getFansList(String user_id, int page, ACallback<FansList> callback) {
        ViseHttp.GET("user/fans/list")
                .tag("getFocusList")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    //获取我的粉丝列表
    public Observable<String> getFansList(String user_id, int page) {
        return ViseHttp.GET("user/fans/list")
                .addParam("user_id", user_id)
                .addParam("page", Integer.toString(page))
                .addParam("limit", "20")
                .request(String.class);
    }

    //关注用户/取消关注
    public void getFocusType(int user_id, AbsCallback<BaseData<FocusType>> callback) {
        ViseHttp.POST("user/toggle/follow")
                .addParam("user_id", Integer.toString(user_id))
                .request(callback);
    }

    //获取视频详情
    public void getVideoInfo(int id, ACallback<BaseData<VideoInfo>> callback) {
        ViseHttp.GET("video/info")
                .addParam("id", Integer.toString(id))
                .request(callback);
    }

    //获取评论
    public void getComment(int videoId, ACallback<CommentBean> callback) {
        ViseHttp.GET("comment/list")
                .addParam("video_id", Integer.toString(videoId))
                .addParam("page", Integer.toString(1))
                .addParam("limit", Integer.toString(Integer.MAX_VALUE))
                .request(callback);
    }

    // 请求金豆奖励
    public void requestGoldReward(String reward_num, AbsCallback<BaseData<GoldBean>> callback) {
        requestGoldReward(reward_num, false, callback);
    }

    public void requestGoldReward(String reward_num, boolean isDouble, AbsCallback<BaseData<GoldBean>> callback) {
        ViseHttp.POST(isDouble ? "gift/double" : "gift/base")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("point", reward_num)
                .addParam("event", "home_bubble")
                .request(callback);
    }

    //推送获取金豆
    public void requestGoldReward(AbsCallback<BaseData<GoldBean>> callback) {
        ViseHttp.POST("gift/base")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .addParam("event", "push_window")
                .request(callback);
    }


    public Observable<String> getCommentList(int page, String videoId) {
        return ViseHttp.GET("comment/list")
                .addParam("video_id", videoId)
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);

    }

    //评论通知列表
    public Observable<String> getNoticeLoveList(int page) {
        return ViseHttp.GET("notification/praise/list")
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    //评论通知列表
    public Observable<String> getNoticeCommentList(int page) {
        return ViseHttp.GET("notification/comment/list")
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    //系统小助手通知列表
    public Observable<String> getNoticeList(int page) {
        return ViseHttp.GET("notification/notice/list")
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    //超链接部分奖励金豆接口
    public void getRewardPoint(String noticeId, ACallback<RewardPoint> callback) {
        ViseHttp.POST("notification/notice/reward_point")
                .addParam("noticeId", noticeId)
                .request(callback);
    }

    //关注通知列表(用户粉丝)
    public Observable<String> getNoticeFansList(int page) {
        return ViseHttp.GET("notification/fans/list")
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    //搜索用户
    public Observable<String> searchUser(int page, String name) {
        return ViseHttp.GET("user/search")
                .addParam("name", name)
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    //搜索视频
    public Observable<String> searchVideo(int page, String name) {
        return ViseHttp.GET("video/search ")
                .addParam("name", name)
                .addParam("page", page + "")
                .addParam("limit", 20 + "")
                .request(String.class);
    }

    // 视频点播上传需要的SecurityToken相关信息
    public void postStsInfo(ACallback<BaseData<StsInfo>> callback) {
        ViseHttp.POST("video/assume/role")
                .request(callback);
    }


    public void getUploadAuth(String title, String filename, ACallback<String> callback) {
        ViseHttp.GET("video/getUploadAuth")
                .addParam("title", title)
                .addParam("filename", filename)
                .request(callback);
    }

    // 点赞/取消点赞
    public void commentPraise(boolean isLevel2, String commentId, ACallback<BaseData<CommentEntity>> callback) {
        ViseHttp.POST(isLevel2 ? "reply/toggle/like" : "comment/toggle/like")
                .addParam("id", commentId)
                .request(callback);
    }

    //评论视频
    public void totore(int videoId, String text, AbsCallback<BaseData<StoreBean>> callback) {
        ViseHttp.POST("comment/store")
                .addParam("video_id", Integer.toString(videoId))
                .addParam("content", text)
                .request(callback);
    }

    //回复评论
    public void replyStore(int storeId, String text, AbsCallback<BaseData<ReplyStoreBean>> callback) {
        ViseHttp.POST("reply/store")
                .addParam("comment_id", Integer.toString(storeId))
                .addParam("content", text)
                .request(callback);
    }

    //回复评论
    public void replyComment(String id, String content, ACallback<BaseData<VideoCommentEntity>> callback) {
        ViseHttp.POST("comment/store")
                .addParam("video_id", id)
                .addParam("content", content)
                .request(callback);
    }

    // 回复评论 回复二级评论
    public void replyLevel2Comment(String commentId, String toUserId, String content, ACallback<BaseData<VideoCommentEntity>> callback) {
        ViseHttp.POST("reply/store")
                .addParam("comment_id", commentId)
                .addParam("content", content)
                .addParam("to_user_id", toUserId)
                .request(callback);
    }

    /**
     * @param is2Level 2级回复
     * @param id
     * @param callback
     */
    public void deleteVideoComment(boolean is2Level, String id, ACallback<BaseData<String>> callback) {
        // reply/delete
        ViseHttp.POST(is2Level ? "reply/delete" : "comment/delete")
                .addParam("id", id)
                .request(callback);
    }

    /**
     * 获取评论列表
     *
     * @param id
     * @param page
     * @param limit
     * @param callback
     */
    public void getReplyListData(String id, int page, int limit, ACallback<String> callback) {
        ViseHttp.GET("reply/list")
                .addParam("comment_id", id)
                .addParam("page", page + "")
                .addParam("limit", limit + "")
                .request(callback);
    }

    //获取评论
    public void getComment(String videoId, ACallback<String> callback) {
        ViseHttp.GET("comment/list")
                .addParam("video_id", videoId)
                .request(callback);
    }

    //点赞和取消点赞
    public void toToggleLike(int id, AbsCallback<BaseData<ToggleLikeBean>> callback) {
        ViseHttp.POST("video/toggle/like")
                .addParam("id", Integer.toString(id))
                .request(callback);
    }

    //我的钱包
    public void getWallet(AbsCallback<BaseData<Wallet>> callback) {
        ViseHttp.GET("me/wallet")
                .request(callback);
    }

    //视频数+1
    public void toForwardIncrease(AbsCallback<BaseData<ForwardIncreaseBean>> callback) {
        ViseHttp.POST("video/forward/increase")
                .addParam("video_id", Store.getInstance().getVideoId())
                .request(callback);
    }

    //上传图片得到URL
    public void getUploadImg(File file, ACallback<UpImage> callback) {
        String baseUrl = BuildConfig.ENABLE_DEBUG ? "https://changdou-admin-dev.kelai.tech/cdn/" : "https://api.changdou.top/cdn/";
        ViseHttp.UPLOAD("upload")
                .baseUrl(baseUrl)
                .addImageFile("upload_file", file)
                .request(callback);
    }

    //用户信息
    public void getUserInfo(String user_id, ACallback<Me> callback) {
        ViseHttp.GET("user/info")
                .addParam("user_id", user_id)
                .addParam("flag", "follow")
                .request(callback);
    }

    // 请求用户引导
    public void getUserGuide(ACallback<String> callback) {
        ViseHttp.GET("gift/getguide")
                .request(callback);
    }

    public void postUserGuide(ACallback<String> callback) {
        ViseHttp.POST("gift/guideupdate")
                .addParam("steps", "19")
                .request(callback);
    }

    //消息通知标记已读
    //类型：praise 点赞通知；评论通知:comment;关注通知follow；小助手通知：notice
    public void markRead(String type, ACallback<BaseData> callback) {
        ViseHttp.POST("notification/mark/read")
                .addParam("type", type)
                .request(callback);
    }

    //消息通知首页
    public void getNotificationInfo(AbsCallback<BaseData<NotificationInfo>> callback) {
        ViseHttp.GET("notification/info")
                .request(callback);
    }

    // 获取到用户banner地址
    public void getUserBannerList(String type, ACallback<String> callback) {
        ViseHttp.GET("personal/banner")
                .addParam("type", type)
                .request(callback);
    }

    //获取品评论通知
    public void getNotificationCommentList(int page, ACallback<Notificattuonpraise> callback) {
        ViseHttp.GET("notification/comment/list")
                .addParam("page", Integer.toString(page))
                .request(callback);
    }


    //获取品赞通知
    public void getNotificationPraiseList(int page, ACallback<Notificattuonpraise> callback) {
        ViseHttp.GET("notification/praise/list")
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    //获取品赞通知
    public void getNotificationNotice(int page, ACallback<Notificattuonpraise> callback) {
        ViseHttp.GET("notification/praise/list")
                .addParam("page", Integer.toString(page))
                .request(callback);
    }

    // 上传视频信息
    public void postVideoInfo(String type, String videoId, String description, String avatar, ACallback<String> callback) {
        ViseHttp.POST("video/store")
                .addParam("type", type)
                .addParam("media_id", videoId)
                .addParam("description", description)
                .addParam("avatar", avatar)
                .request(callback);
    }

    //获取我的黑名单列表
    public void getBlackList(int page, ACallback<BlackList> callback) {
        ViseHttp.GET("user/black/list")
                .addParam("page", Integer.toString(page))
                .request(callback);
    }


    //获取我的黑名单列表
    public Observable<String> getBlackList(int page) {
        return ViseHttp.GET("user/black/list")
                .addParam("page", Integer.toString(page))
                .addParam("limit", 20 + "")
                .request(String.class);
    }


    //添加黑名单
    public void addBlank(String user_id, ACallback<AddBlack> callback) {
        ViseHttp.POST("user/black/add")
                .addParam("user_id", user_id)
                .request(callback);
    }

    //取消黑名单
    public void delBlank(String user_id, ACallback<AddBlack> callback) {
        ViseHttp.POST("user/black/del")
                .addParam("user_id", user_id)
                .request(callback);
    }

    //添加举报
    //tip_off_id	举报理由 1广告诈骗,2淫秽色情,3 骚扰谩骂,4 反动政治
    //type	       	举报类型 user举报用户,video举报视频 ,comment 举报评论,reply举报回复评论
    //type_id	   	如果是举报用户传被举报的用户ID，如果是举报视频被举报的视频ID ，如果是举报回复评论被举报的回复评论ID，如果是举报评论被举报的评论ID
    public void addReport(String tip_off_id, String type, String type_id, ACallback<AddBlack> callback) {
        ViseHttp.POST("user/tip/off")
                .addParam("tip_off_id", tip_off_id)
                .addParam("type", type)
                .addParam("type_id", type_id)
                .request(callback);
    }

    //获取开屏广告
    public void getAdvertOpen(ACallback<BaseData<AdvertInfo>> callback) {
        ViseHttp.GET("advert/open")
                .request(callback);
    }

    //获取信息流广告
    public void getAdvertDraw(int size, ACallback<String> callback) {
        ViseHttp.GET("advert/info")
                .addParam("size", size + "")
                .request(callback);
    }

    //获取激励视频广告
    //type 1签到，2看视频得奖励，3自动播放
    public void getAdvertReward(int type, ACallback<BaseData<AdvertInfo>> callback) {
        ViseHttp.GET("advert/reward")
                .addParam("type", type + "")
                .request(callback);
    }

    //根据ID获取自身广告数据
    public void getPlanById(String planId, ACallback<BaseData<AdvertList>> callback) {
        ViseHttp.GET("advert/getPlanById")
                .addParam("id", planId + "")
                .request(callback);
    }

    //埋点
    public void trackAction(int pageId, String action, String note, ACallback<BaseData> callback) {
        ViseHttp.POST("track")
                .addParam("page_id", pageId + "")
                .addParam("action", action)
                .addParam("note", note)
                .request(callback);
    }

    //记录用户ip
    public void loginRecord(ACallback<BaseData> callback) {
        ViseHttp.POST("login/loginRecord")
                .addHeader("blackbox", ShuaApplication.blackbox)
                .request(callback);
    }

    //广告数据上报
    public void reportAdvertAction(AdvertReport advert, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/action")
                .addParam("plan_id", advert.getPlan_id() + "")
                .addParam("uuid", advert.getUuid())
                .addParam("event", advert.getEvent().toString())
                .addParam("client", advert.getClient() + "")
                .addParam("type", advert.getType() + "")
                .request(callback);
    }

    //广告 请求/返回/异常-数据上报
    public void actionThirdAsk(ActionThirdAsk report, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/action_third_ask")
                .addParam("advert_way", report.advert_way + "")
                .addParam("advert_type", report.advert_type + "")
                .addParam("type", report.type)
                .addParam("code_bit", report.code_bit)
                .addParam("request_num", report.request_num + "")
                .addParam("return_num", report.return_num + "")
                .addParam("error_code", report.error_code)
                .addParam("error_msg", report.error_msg)
                .request(callback);
    }

    /**
     * 穿山甲广告数据上报
     *
     * @param plan_id   广告计划ID
     * @param uuid      请求唯一id
     * @param eventType 执行事件, video_start;video_pause;video_end;video_stop; image_show; video_click; image_click
     * @param type      广告位，1.开屏 2.信息流 3.签到 4.看视频 5.开启自动播放
     * @param way       广告渠道，1穿山甲，2优量汇, 3 百青腾
     * @param callback
     */
    public void reportAdAction(String plan_id, String uuid, AdvertReport.EventType eventType, String type, String way, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/action_third")
                .addParam("plan_id", plan_id + "")
                .addParam("uuid", uuid)
                .addParam("event", eventType.toString())
                .addParam("type", type)
                .addParam("way", way)
                .request(callback);
    }

    /**
     * 记录用户浏览视频标签
     *
     * @param video_id        视频 ID
     * @param start_timestamp 开始时间
     * @param end_timestamp   结束时间
     */
    public void reportVideoTag(int video_id, long start_timestamp, long end_timestamp, ACallback<BaseData> callback) {
        ViseHttp.POST("video/reportVideoTag")
                .addParam("video_id", video_id + "")
                .addParam("start_timestamp", start_timestamp + "")
                .addParam("end_timestamp", end_timestamp + "")
                .request(callback);
    }

    /**
     * 热点视频观看数量加一
     *
     * @param video_id   视频 ID
     * @param video_star 视频观看开始时间
     * @param video_end  视频观看结束时间
     * @param callback
     */
    public void reportHotWatch(int video_id, long video_star, long video_end, ACallback<BaseData> callback) {
        ViseHttp.POST("video/hotwatch/increase")
                .addParam("video_id", video_id + "")
                .addParam("video_star", video_star + "")
                .addParam("video_end", video_end + "")
                .request(callback);
    }

    /**
     * 渠道数据上报接口，点击数、下载数、打开数、注册数等
     *
     * @param channel_type  渠道类型 例：穿山甲-CSJ
     * @param channel_event 渠道事件 1-点击数 2-下载数 3-注册数
     */
    public void reportChannelData(String channel_type, int channel_event, ACallback<BaseData> callback) {
        ViseHttp.POST("channel/data")
                .addParam("channel_type", channel_type)
                .addParam("channel_event", channel_event + "")
                .request(callback);
    }

    //修改任务状态
    public void reportGiftAction(GiftReport.EventType advert, ACallback<BaseData> callback) {
        ViseHttp.POST("gift/update")
                .addParam("event", advert.toString())
                .request(callback);
    }

    //H5分享防封换域名
    public void domain(ACallback<BaseData> callback) {
        ViseHttp.POST("setting/domain")
                .request(callback);
    }

    //搜索视频
    public Observable<String> getHot1(int page) {
        return ViseHttp.GET("hotvideo/videolist")
                .addParam("page", page + "")
                .addParam("limit", 10 + "")
                .request(String.class);
    }

    // 热点视频
    public Observable<String> getHotList(int page, int size) {
        return ViseHttp.GET("home/getHotVideo")
                .addParam("page", page + "")
                .addParam("limit", size + "")
                .request(String.class);
    }

    //开启某些用户开关功能
    public void getSwitch(int switch_id, ACallback<BaseData> callback) {
        ViseHttp.POST("switch/create")
                .addParam("switch_id", switch_id + "")
                .request(callback);
    }

    //瓜分活动开关
    public void gfstatus(String type, ACallback<BaseData<Guafen>> callback) {
        ViseHttp.GET("activity/gfstatus")
                .addParam("type", type)
                .request(callback);
    }

    //弹窗送金豆
    public void getReward(ACallback<BaseData<Reward>> callback) {
        ViseHttp.GET("activity/popup/getReward")
                .request(callback);
    }

    //埋点点
    // game_type	是	int	类型 1：弹窗 2：系统小助手
    //notice_id	否	int	类型 2：系统小助手 该参数必须
    //popup_id	否	int	类型 1：弹窗 该参数必须

    public void get_record_num(String game_type, String popup_id, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/get_record_num")
                .addParam("game_type", game_type)
                .addParam("popup_id", popup_id)
                .request(callback);
    }

    //埋点点
    // game_type	是	int	类型 1：弹窗 2：系统小助手
    //notice_id	否	int	类型 2：系统小助手 该参数必须
    //popup_id	否	int	类型 1：弹窗 该参数必须

    public void get_record_num1(String game_type, String notice_id, ACallback<BaseData> callback) {
        ViseHttp.POST("advert/get_record_num")
                .addParam("game_type", game_type)
                .addParam("notice_id", notice_id)
                .request(callback);
    }


    private static class SingletonHolder {
        private static final HttpData INSTANCE = new HttpData();
    }

    public static HttpData getInstance() {
        return SingletonHolder.INSTANCE;
    }

    /**
     * @param url
     * @param callback
     */
    public void downloadApk(String url, ACallback<DownProgress> callback) {
        if (TextUtils.isEmpty(url)) {
            callback.onFail(100, "下载地址不能为空！");
            return;
        }
        if (!url.startsWith("http")) {
            callback.onFail(110, "下载地址错误！");
            return;
        }
        Uri uri = Uri.parse(url);
        String baseUrl = uri.getScheme() + "://" + uri.getAuthority() + "/";
        ViseHttp.DOWNLOAD(url)
                .baseUrl(baseUrl)
                .setFileName(MD5Util.encryptMD5ToString(url) + ".apk")
                .request(callback);
    }

}